# -*- coding: UTF-8 -*-
import os
import sys
import math as m

from os.path import dirname
from time import clock

root = dirname(dirname(__file__))
sys.path.append(root)
os.chdir(root)

from objects3d.BasicObjects import BaseObject

'''
Created on 03.02.2013

@author: Peter Heß, Germany

samples from vvvv how they do it:

Centered/-/-/Phase=.50/Count=11
0.0455, 0.1364, 0.2273, 0.3182, 0.4091, -0.5000, -0.4091, -0.3182, -0.2273, -0.1364, -0.0455

Centered/-/-/Phase=.75/Count=11
0.2955, 0.3864, 0.4773, -0.4318, -0.3409, -0.2500, -0.1591, -0.0682, 0.0227, 0.1136, 0.2045

'''

class LFO(BaseObject):
    '''
        Creates values during the loop processing form 0..1
    '''
  
    def __init__(self, Period_in=1.0, Reverse_in=0 ):
        BaseObject.__init__(self)
        self.Period_in = Period_in
        if (Reverse_in >= 1):
            self.Reverse_in = 1
        else:
            self.Reverse_in = 0
        self.update();
  
    def update(self, Period_in=None, Reverse_in=None):

        if (Period_in != None and self.Period_in != Period_in): 
            self.Period_in = Period_in
        if (Reverse_in != None and self.Revers_in != Reverse_in): 
            self.Reverse_in = Reverse_in

        if (self.Reverse_in >= 1):
            self.Reverse_in = 1
        else:
            self.Reverse_in = 0

        self.Output = [m.fabs(self.Reverse_in - ((clock() % self.Period_in) / self.Period_in))] 

    def Output(self):            
        return self.Output

